<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title>Liste des entreprises - Base Carnet d'adresse</title>
        <link href="liste.css" type="text/css" rel="stylesheet">
    </head>
    <body>
        <?php
            $hote="localhost";
            $utilisateur="admin";
            $mdp="";
            $bdd="carnet_adresses";
            
            $idconnex=  mysqli_connect($hote, $utilisateur, $mdp, $bdd);

            
            if (mysqli_connect_errno()) {
                echo ("Echec de la connexion : erreur n°". mysqli_connect_errno()." / ". mysqli_connect_error());
            } 
            else { 
                echo "Connexion au serveur MySQL > OK !<br><br>";
            }
            
            $req1='SELECT * FROM entreprises';
            if (!isset($tri)) {$tri="";}
            $req1=$req1 . " " . $tri;
            $resultat_req1 =  mysqli_query($idconnex, $req1);
            
            $req2='SELECT COUNT(*) FROM entreprises';
            $resultat_req2 = mysqli_query($idconnex, $req2);
            $nb_entreprises=  mysqli_fetch_array($resultat_req2);            
            
            ?>
        <div>LISTE DES ENTREPRISES</div><br>
        <div><a href='liste_entreprises.php?tri=ORDER BY raison_sociale ASC'> Afficher tous (croissant) </a> / 
            <a href='liste_entreprises.php?tri=ORDER BY raison_sociale DESC'> Afficher tous (décroissant)</a></div><br><br>
        <div>Nombre d'entreprises affich&eacute; : <?php echo $nb_entreprises[0] ;?></div><br>

            <?php 
            while ($donnees = mysqli_fetch_assoc($resultat_req1)) {
                echo "<table>";
                echo "<tr><td class=\"col1\">n°</td><td class=\"col2\">" . $donnees['id'] . "</td></tr>";
                echo "<tr><td class=\"col1\">Raison sociale</td><td class=\"col2\"><a href=\"liste_contacts.php?tri= &critere= WHERE id_entreprise='" .$donnees['id']. "'\">" . $donnees['raison_sociale'] . "</td></tr>";
                echo "<tr><td class=\"col1\">Adresse</td><td class=\"col2\">" . $donnees['adresse'] . "</td></tr>";
                echo "<tr><td class=\"col1\">T&eacute;l&eacute;phone</td><td class=\"col2\">" . $donnees['telephone'] . "</td></tr>";
                echo "<tr><td class=\"col1\">Fax</td><td class=\"col2\">" . $donnees['fax'] . "</td></tr>";
                echo "<tr><td class=\"col1\">E-mail</td><td class=\"col2\">" . $donnees['email'] . "</td></tr>";
                echo "<tr><td class=\"col1\">Observations</td><td class=\"col2\">" . $donnees['observations'] . "</td></tr>";
                echo "</table>";
                echo "<br>";
            }
        ?>
    </body>
</html>
